import Pancake from "./pancake.js";
import PancakeDecorator from "./pancake-decorator.js";

// 煎饼果子加鸡蛋
class PancakeDecoratorWithEgg extends PancakeDecorator {
  // 获取煎饼果子加鸡蛋的名字
  getName() {
    return `${this.pancake.getName()}➕鸡蛋`;
  }

  getPrice() {
    return this.pancake.getPrice() + 2;
  }
}

// 加香肠
class PancakeDecoratorWithSausage extends PancakeDecorator {
  // 加香肠
  getName() {
    return `${this.pancake.getName()}➕香肠`;
  }

  getPrice() {
    return this.pancake.getPrice() + 1.5;
  }
}

// 加培根
class PancakeDecoratorWithBacon extends PancakeDecorator {
  // 加培根
  getName() {
    return `${this.pancake.getName()}➕培根`;
  }

  getPrice() {
    return this.pancake.getPrice() + 3;
  }
}

let pancake;
const el = (id) => document.getElementById(id);
const handleClick = (ele, fn) => ele.addEventListener('click', () => {
  fn();
  console.log(pancake.getName(), pancake.getPrice())
  el('info').innerHTML = `你的煎饼果子包含：${pancake.getName()}，需要花费${pancake.getPrice()}元`
});
handleClick(el('pancake'), () => {
  pancake = new Pancake();
})
handleClick(el('egg'), () => {
  pancake = new PancakeDecoratorWithEgg(pancake);
})
handleClick(el('sausage'), () => {
  pancake = new PancakeDecoratorWithSausage(pancake);
})
handleClick(el('bacon'), () => {
  pancake = new PancakeDecoratorWithBacon(pancake);
})


// let pancake = new Pancake();
// // 加鸡蛋
// pancake = new PancakeDecoratorWithEgg(pancake);
// console.log(pancake.getName(), pancake.getPrice());
// // 加香肠
// pancake = new PancakeDecoratorWithSausage(pancake);
// console.log(pancake.getName(), pancake.getPrice());
// // 加培根
// pancake = new PancakeDecoratorWithBacon(pancake);
// console.log(pancake.getName(), pancake.getPrice());
